<?php

class Mod_class_manager extends Model {

    function Mod_class_manager() {
        parent::model();
    }

    function index() {
     
    }
   //===========================function for select view manger======================//
    function select_class(){
        
        return $this->db->query('SELECT * FROM tbl_class');
        
    }
//======================this is pagination========================//
    
       function get_page_limit($start_row, $per_page) {
        $query = "SELECT *FROM tbl_class limit $start_row,$per_page";
        $result = $this->db->query($query);
        return $result;
    }
    
    //====================function for add new class=======================//
    
    function addclass() {
        
        $classname = $this->input->post('txtclassname');
        $classdescription = $this->input->post('txtdetail');
        $data = array(
            'cla_name' => $classname,
            'cla_description' => $classdescription,
            'cla_status'=>1
        );
        return $this->db->insert('tbl_class', $data);
    }
    
//========================function for deleted class=======================//
    
    function delete() {
        
        $seg = $this->uri->segment('3');
        $this->db->where('cla_id', $seg);
        return $this->db->delete('tbl_class');
    }
    
//================function for selecting edit class====================//
    
    function selet_edit() {
        
        $id = $this->uri->segment('3');
        $this->db->where('cla_id', $id);
        return $this->db->get('tbl_class');
    }
    
//========================= function for checkedit class=================//
    
    function checkedit() {

        $dataproduct = array(
            'cla_name' => $this->input->post('txtclassname'),
            'cla_description' => $this->input->post('txtdetail'),
        );

        $id = $this->uri->segment('3');
        $this->db->where('cla_id', $id);
        return $this->db->update('tbl_class', $dataproduct);
    }
    //=====================function for select detail in the class=================//
    
    function select_detail(){
        $id=$this->uri->segment('3');
        $this->db->select('*');
        $this->db->from('tbl_class');
        $this->db->where('cla_id',$id);
        return $this->db->get();
    }
    
    //==============================function for searching class=======================//
       function get_teachers($p=null) { // $p is array
        if ($this->input->post($this->dbf->cla_name) && $this->input->post($this->dbf->cla_name) != '')
        $this->db->like($this->dbf->cla_name, $this->input->post($this->dbf->cla_name));
        $this->db->limit($p[0], $p[1]);
        $this->db->where('cla_status',1);
        $this->db->order_by('cla_id','desc');
        return $this->db->get('tbl_class');
    }

}
